library(tidyverse)

# set replication folder as working directory
setwd("~replication")

load("data_genderedcost_long.rdata")

df_long <- df_long %>% 
  filter(SurveyStatus==2) %>% 
  filter(SurveyEndTime<="2021-12-20 21:49:52")


### FIGURE H1
mm_overall <- cregg::mm(df_long, # data
                        choice~ work_environment+workload+remuneration+position, # formula
                        id = id)

## rename feature factor and reorganize it
mm_overall <- mm_overall %>% 
  mutate(feature = case_when(feature=="work_environment"~"Working Environment",
                             feature=="workload"~"Workload",
                             feature=="remuneration"~"Remuneration",
                             feature=="position"~"Position")) %>% 
  mutate(feature = factor(feature, levels = c("Position", "Remuneration", "Workload", "Working Environment")))


## plot overall marginal means
mm_overall %>%
  ggplot(data=., aes(y = level, x = estimate)) +
  geom_point(color = "black") +
  geom_linerange(aes(xmin=lower,
                     xmax=upper),
                 #size=1,
                 color = "black") +
  xlab("Marginal mean") +
  ylab("") +
  scale_x_continuous(labels = seq(0.3,0.8,0.05), breaks = seq(0.3,0.8,0.05)) +
  geom_vline(xintercept = 0.5, linetype = "dashed") +
  theme_bw() +
  facet_wrap(~feature, scales = "free_y", ncol = 1) +
  theme(legend.position = "none", panel.background = element_rect(fill = "white"),
        strip.background = element_rect("white"),
        strip.text = element_text(hjust = 0, face = "bold"),
        panel.grid.major = element_blank(), panel.grid.minor = element_blank())

ggsave("figureH1.pdf", height = 5, width = 8)
